package com.example.lab2cv;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.os.Bundle;
import android.app.Activity;
import android.app.Fragment;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;

public class Map extends Fragment {
	static final LatLng WIZARDS = new LatLng(47.4648, -122.2220);
	private GoogleMap map;
	private static View view;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		if (view != null) {
			ViewGroup parent = (ViewGroup) view.getParent();
			if (parent != null)
				parent.removeView(view);
		}
		try {
			view = inflater.inflate(R.layout.activity_map, null, false);
		} catch (InflateException e) {

		}

		map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
				.getMap();

		if (map != null) {
			map.addMarker(new MarkerOptions().position(WIZARDS)
					.title("Wizards of the Coast")
					.snippet("1600 Lind Ave SW #400, Renton, WA 98057, USA"));

			// Move the camera instantly to wizards with a zoom of 15.
			map.moveCamera(CameraUpdateFactory.newLatLngZoom(WIZARDS, 15));

			// Zoom in, animating the camera.
			map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
		}
		return view;
	}

}
